package com.client.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.client.model.ISpCodeBanTime;
import com.client.model.ISpCodeConfirm;
import com.client.model.ISpCodeFilter;
import com.client.model.ISpCodeProvince;
import com.manage.config.Config;
import com.service.AbstractService;
import com.util.ConfigUtil;
import com.util.Util;
import com.utils.dbcp.ModelGenerator;

public class ISpCodePrvinceServiceImpl extends AbstractService implements ISpCodePrvinceService {
	private Logger logger;
	public ISpCodePrvinceServiceImpl()
	{
		logger = Logger.getLogger(this.getClass());
		this.dbcp = ConfigUtil.get(Config.SECTION, Config.KEY_DBCP_NAME);
	}
	@Override
	public List<ISpCodeProvince> getAll() {
		String date = Util.dateToString(new Date());
		String sql = "select a.id id,a.spid spid,a.codename codename,a.carrier carrier," +
				"a.orderType orderType,a.codeType codetype,a.smspayport smspayport," +
				" a.smspaycode smspaycode,a.basepayaction basepayaction,a.baseparameter baseparameter,a.level level," +
				" a.codestatus codeStatus,b.provinceCode provinceCode,b.shieldRegion shieldRegion,b.feeValue feeValue," +
				"b.dailyLimit dailyLimit,b.monthlyLimit monthlyLimit," +
				"b.dailyCapacity dailyCapacity,b.monthlyCapacity monthlyCapacity" +
				",a.codefeevalue codefeevalue,a.codedailylimit codedailylimit,a.codemonthlylimit codemonthlylimit," +
				"a.codedailycapacity codedailycapacity,a.codemonthlycapacity codemonthlycapacity,a.codeua codeua,a.space space " +
				" from spcode a,spcodeprovince b where a.id = b.spcodeid and (a.codestatus='0' or a.codestatus='2')" +
				" and a.startdate<='"+date+"' and a.expireddate>='"+date+"' order by a.level desc,a.id desc";
		logger.info(sql);
		ModelGenerator<ISpCodeProvince> dbcpmg = new ModelGenerator<ISpCodeProvince>(ISpCodeProvince.class);
		return dbcpmg.generateList(dbcp, sql);
	}
	@Override
	public List<ISpCodeBanTime> getSpCodeBanTimes() {
		String sql = "select * from spcodebantime order by createdate desc";
		ModelGenerator<ISpCodeBanTime> dbcpmg = new ModelGenerator<ISpCodeBanTime>(ISpCodeBanTime.class);
		return dbcpmg.generateList(dbcp, sql);
	}
	@Override
	public List<ISpCodeConfirm> getSpCodeConfirms() {
		String sql = "select * from spcodeconfirm order by createdate desc";
		ModelGenerator<ISpCodeConfirm> dbcpmg = new ModelGenerator<ISpCodeConfirm>(ISpCodeConfirm.class);
		return dbcpmg.generateList(dbcp, sql);
	}
	@Override
	public List<ISpCodeFilter> getSpCodeFilters() {
		String sql = "select * from spcodefilter  order by createdate desc";
		ModelGenerator<ISpCodeFilter> dbcpmg = new ModelGenerator<ISpCodeFilter>(ISpCodeFilter.class);
		return dbcpmg.generateList(dbcp, sql);
	}
	

}
